home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12893 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Can anyone HELP with variable delaration? Please?
  5. Date: 3 Apr 1996 12:38:53 GMT
  6. Organization: systems hk
  7. Message-ID: <4jtrgt$h77@nadine.teleport.com>
  8. References: <4jt07b$dul@news.us.net>
  9. NNTP-Posting-Host: ip-pdx01-07.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. sillybug@us.net (brian skrab) wrote:
  16. >Hello,
  17. >
  18. >I've just started learning C programming (moving up from Pascal) and I can't 
  19. >seem to find an answer to this question.  I'm sure this is going to sound 
  20. >stupid, but how can I declare a variable to be of a data type string?  Is 
  21. >there a data type "string"?
  22. >
  23. Brian,
  24.  
  25. A 'string' in C is typically an array of characters, or a pointer to
  26. a contiguous group of zero or more characters:
  27.  
  28.   char  arrayOfChars[80];   /* array of 80 characters */
  29.   char  *ptrToChars;        /* pointer to characters (which don't exist yet) */
  30.   ...
  31.   ptrToChars = (char *)malloc( 80 );  /* if successful, they do now (check for zero) */
  32.   ...
  33.   strcpy( arrayOfChars,"FirstName" );
  34.   strcpy( ptrToChars,"LastName" );
  35.   ...
  36.  
  37. Yours, Geoff Houck
  38.  
  39.